﻿using System.Linq;
using MvcContrib.Pagination;

namespace DevelopmentKit.Extensions.MvcContrib
{
    public static class PaginationHelper
    {
        /// <summary>
        /// 获取分页列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="pageNumber"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public static IPagination<T> AsPagination<T>(this IQueryable<T> source, int pageNumber, int pageSize)
        {
            var list = source.Skip((pageNumber - 1)*pageSize).Take(pageSize).ToList();
            return new CustomPagination<T>(list, pageNumber, pageSize,
                                           source.Count());
        }
    }
}